/* 
 * File:   Auxiliar.cpp
 * Author: Henrique
 * 
 * Created on 28 de Setembro de 2011, 09:36
 */

#include "Auxiliar.h"


Auxiliar::Auxiliar() {
}

Auxiliar::Auxiliar(const Auxiliar& orig) {
}

Auxiliar::~Auxiliar() {
}

string Auxiliar::fileName(string path, string extension, int i) {
	stringstream name;
	name << path << i << "." <<extension;
	return name.str();
}


/*
 * Find the maximum value at an array.
 * @param array The array that will have its maximum element detected.
 * @param arraySize The size of the array.
 */
double Auxiliar::maxValue(double * array, int arraySize) {
	double max = array[0];
	for (int i = 1; i < arraySize; i++) {
		if (max < array[i]) {
			max = array[i];
		}
	}
	return max;
}

void Auxiliar::createArchieve(string name, double * array, int arraySize) {
	ofstream arquivo;
	arquivo.open(name.c_str());

	for (int i = 0; i < arraySize; i++) {
		arquivo << array[i] << endl;
	}
	arquivo.close();
}

void Auxiliar::createArchieve(string name, string content) {
	ofstream arquivo;
	arquivo.open(name.c_str());
	arquivo << content;
	arquivo.close();
}


double Auxiliar::findNumberBlackPixels(IplImage* image, int height, int width) {
    double sum = 0;
    for (int i = 3; i < height - 3; i++) {
        for (int j = 3; j < width - 3; j++) {
            if (cvGetReal2D(image, i, j) == 0) {
                sum++;
            }
        }
    }
    return sum;
}
